package com.coder.util;

import java.util.Arrays;
import java.util.Collection;

/**
 * 添加新行并缩排所有元素的工具
 *
 * @author yuhushuan
 * @date 2020/8/19 12:28
 */
public class PPrint {
    public static String format(Collection<?> c) {
        if (c.size() == 0) {
            return "[]";
        }
        StringBuilder result = new StringBuilder("[");
        for (Object elem : c) {
            if (c.size() != 1) {
                result.append("\n ");
            }
            result.append(elem);
        }
        if (c.size() != 1) {
            result.append("\n");
        }
        result.append("]");
        return result.toString();
    }

    public static void println(Collection<?> c) {
        System.out.println(format(c));
    }

    public static void println(Object[] c) {
        System.out.println(format(Arrays.asList(c)));
    }
}
